package com.clpms.controller;

import com.clpms.bean.req.AddCourseReq;
import com.clpms.bean.req.CourseQueryReq;
import com.clpms.bean.req.DeleteCourseReq;
import com.clpms.bean.req.UpdateCourseReq;
import com.clpms.bean.resp.CourseQueryResp;
import com.clpms.service.CourseService;
import com.clpms.utils.ResultDto;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author caixinyong
 * @date 2023/5/9 7:59 PM
 */

@RestController
@RequestMapping("/course/v1")
@Slf4j
public class CourseController {

	@Resource
	private CourseService courseService;

	/**
	 * 查询课程信息
	 *
	 * @param req
	 * @return
	 */
	@PostMapping("/queryCourse")
	ResultDto<PageInfo<CourseQueryResp>> query(@RequestBody @Valid CourseQueryReq req) {
		PageInfo<CourseQueryResp> pageInfo = courseService.query(req);
		return ResultDto.Success(pageInfo);
	}

	@PostMapping("/queryAllCourse")
	ResultDto<List<CourseQueryResp>> queryAllCourse() {
		List<CourseQueryResp> respList = courseService.queryAllCourse();
		return ResultDto.Success(respList);
	}

	@PostMapping("/deleteCourse")
	ResultDto<Boolean> delete(@RequestBody @Valid DeleteCourseReq req) {
		Boolean result = courseService.delete(req);
		return ResultDto.Success(result);
	}

	@PostMapping("/addCourse")
	ResultDto<Boolean> addCourse(@RequestBody @Valid AddCourseReq req) {
		Boolean result = courseService.addCourse(req);
		return ResultDto.Success(result);
	}

	@PostMapping("/updateCourse")
	ResultDto<Boolean> updateCourse(@RequestBody @Valid UpdateCourseReq req) {
		Boolean result = courseService.updateCourse(req);
		return ResultDto.Success(result);
	}
}
